package com.cn.项目.飞机预约管理系统.UserFrame;

import com.cn.项目.utils.JdbcUtils;

import javax.swing.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import static com.cn.项目.飞机预约管理系统.UserFrame.SelectStartEnd.*;

public class SFilghtJpanel extends JPanel {
    Vector rowDate, columnNames;
    JTable jt;
    JScrollPane jsp;

    public SFilghtJpanel(){
        Connection conn = null;
        PreparedStatement st = null;
        ResultSet rs =null;
        columnNames = new Vector();
        columnNames.add("出发日期");
        columnNames.add("出发地");
        columnNames.add("出发时间");
        columnNames.add("目的地");
        columnNames.add("到达时间");
        columnNames.add("价钱");

        rowDate = new Vector();
        try {
            conn = JdbcUtils.getConnection();
            String sql = "select  *from flight where start=?and `end` =?and traveldate=?and fmoney=?";
            st = conn.prepareStatement(sql);
            System.out.println("Start:"+start);
            System.out.println("end:"+endlocation);
            st.setString(1,start );
            st.setString(2,endlocation);
            st.setString(3,date);
            st.setString(4,money);
            rs = st.executeQuery();
            while (rs.next()) {
                Vector hang = new Vector();
                hang.add(rs.getString(1));
                hang.add(rs.getString(2));
                hang.add(rs.getString(3));
                hang.add(rs.getString(4));
                hang.add(rs.getString(5));
                hang.add(rs.getString(6));
                rowDate.add(hang);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JdbcUtils.release(conn, st, rs);
        }

        jt = new JTable(rowDate, columnNames);
        jsp = new JScrollPane(jt);
        this.add(jsp);
        this.setVisible(true);
    }
}
